import pygame

# inicializar pygame
pygame.init()
SIZE = (800,600)
screen = pygame.display.set_mode(SIZE)

# cargar recursos
fondo = pygame.image.load("fondo.jpg").convert_alpha()
class GrossiniSprite(pygame.sprite.Sprite):
    image = pygame.image.load("grossini.png").convert_alpha()

# inicializar simulacion
grossini = GrossiniSprite()
grupo = pygame.sprite.Group(grossini)
x=0

# repetir
running = True
screen.blit( fondo, (0,0) )
clock = pygame.time.Clock()
while running:
    # 1-Procesar acciones
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
        elif event.type == pygame.KEYDOWN:
            if event.key == pygame.K_ESCAPE:
                running = False
    # 2-Avanzar simulacion
    clock.tick(30)
    x = (x+15)%screen.get_rect().width
    y = screen.get_rect().centery
    grossini.rect = grossini.image.get_rect(centery=y, centerx=x)
    # 3-Dibujar estado actual
    grupo.clear( screen, fondo )
    grupo.draw( screen )
    pygame.display.flip()
